Clear["Global`*"];ThingL1={};ThingL2={};ThingN1={};ThingN2={}; ThingA1={};ThingA2={}; ThingL3={}; ThingN3={}; ThingH1={}; ThingH2={};  ThingH3={}; AnotherThing={};
groups=(({{Cat, B1, B2, B3, B4, B5, B6, B7, B8, HA1, HA2, HA3, HA4, HA5, HB1, HB2, HB3, HB4, HB5, HC1, HC2, HC3, HC4, HC5, M1, M2, M3, G1, G2, G3, G4, G5, G6, G7, G8, G9, G10, W1, W2, W3, P1, P2, P3, P4, P5}, {RowNo, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45}, {a, -0.80, 0.49, 1.44, 2.26, 2.83, 3.27, 3.86, 4.62, 0.75, 1.53, 2.36, 3.48, 4.45, 0.28, 1.34, 1.97, 2.62, 3.93, -0.40, 0.61, 1.37, 1.91, 3.44, -1.03, 0.22, 1.85, 1.58, 2.47, 2.85, 3.17, 3.40, 3.63, 3.94, 4.25, 4.56, 5.01, 2.60, 3.91, 4.64, 1.54, 2.41, 3.01, 3.64, 4.30}, {b, 10.10, 11.25, 12.08, 12.70, 13.15, 13.53, 14.00, 14.60, 11.41, 12.28, 12.80, 13.19, 13.70, 11.00, 11.91, 12.48, 13.10, 13.78, 10.55, 11.52, 12.18, 12.69, 13.40, 8.91, 9.86, 10.96, 11.71, 12.57, 12.95, 13.22, 13.44, 13.67, 13.96, 14.26, 14.54, 14.93, 13.67, 14.52, 15.09, 12.39, 12.99, 13.48, 13.96, 14.55}, {RedD, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 15, 15, 15, 15, 15, 0.1, 0.1, 0.1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 2, 2, 2, 2, 2}, {Gr, 0, 0, 0, 0, 0, 0, 0, 0, 100, 100, 100, 100, 100, 50, 50, 50, 50, 50, 0, 0, 0, 0, 0, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {Ha, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {SM, 0, 0, 0, 0, 0, 0, 0, 0, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11400, 11400, 11400, 4250, 4250, 4250, 4250, 4250}, {Brd, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 365, 365, 365, 35, 35, 35, 35, 35}, {RoeD, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 2, 2, 2, 2, 2}}));
habitat=40;
increase=2.5;

host=2;
a=Part[groups, 3, habitat]+increase; b=Part[groups, 4, habitat]+increase;  TL1=8; TL2=12; TNA1=5; TNA2=9; bL=0.047;bN=0.024; bA=0.009;bowL=0.00995;bowN=0.00333; egg=627.5; ϵ=0.0000001;
Fzero=50;  
bH=If[host==1, 0.0192, 0.0064]; aH=If[host==1, 0.4615, 0.1538]; σ=0.01675; sH=If[host==1, 0.004423, 0.001474]*(100/(HS0=If[host==1, Part[groups, 8, habitat], Part[groups, 9, habitat]])); 
InitialInf=0.1;
L0=100000; NS0=10000*(1-InitialInf);NI0=10000*InitialInf; A0=1000; HS0=If[host==1, Part[groups, 8, habitat], Part[groups, 9, habitat]]; HI0=0; HR0=0;
Ymax=100;
hosts=(({{RedDeer, Part[groups, 5, habitat], 15.18, 70.41, 81.25}, {Grouse, Part[groups, 6, habitat], 15, 4, 0}, {Hare, Part[groups, 7, habitat], 63.7, 37.4, 11.4}, {SmallMammal, If[host==1, 0, Part[groups, 8, habitat]] , 1.61, 0.03, 0}, {Bird, If[host==2, 0, Part[groups, 9, habitat]], 3.11, 0.25, 0}, {RoeDeer, Part[groups, 10, habitat], 10.78, 23.9, 29.82}}));
hvalues=Transpose[hosts].hosts;

HL=If[host==1, 1.61, 3.11];
HN=If[host==1, 0.03, 0.25];

Do[
T[t_]=(((b-a)/2)*Sin[(t/(2.6π))-0.5π])+((b+a)/2);
FL[t_]:=(Piecewise[{{0, T[t]⩽TL1}, {((T[t]-TL1)/(TL2-TL1)), TL1<T[t]<TL2}, {1, T[t]⩾TL2}}]);
FNA[t_]:=(Piecewise[{{0, T[t]⩽TNA1}, {((T[t]-TNA1)/(TNA2-TNA1)), TNA1<T[t]<TNA2}, {1, T[t]⩾TNA2}}]);
P[t_]=(1/(1+Exp[0.75(8-T[t])]));
S[x_,K_]:=((K*Fzero)/(Fzero+(K-Fzero)*Exp[((Log[(Fzero/(19*(K-Fzero)))])/(8*K))*x]))-Fzero;
HB[t_]:=(Piecewise[{{0, Mod[t,52]⩽19}, {1, 19<Mod[t,52]⩽22}, {0, Mod[t,52]⩾23}}]);
soln=NDSolve[{
LQ'[t]==-S[FL[t]*P[t]*LQ[t], Part[hvalues,2,3]+HL*(HS[t]+HI[t]+HR[t])]-bL*LQ[t],
LMS'[t]==(1-(( HI[t]*HL)/(Part[hvalues, 2, 3]+HL(HS[t]+HI[t]+HR[t]))))*S[FL[t]*P[t]*LQ[t], Part[hvalues,2,3]+HL*(HS[t]+HI[t]+HR[t])]-bowL*LMS[t],
LMI'[t]==(( HI[t]*HL)/(Part[hvalues, 2, 3]+HL(HS[t]+HI[t]+HR[t])))*S[FL[t]*P[t]*LQ[t], Part[hvalues,2,3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(Y-1)*52]==A0, 
AM[(Y-1)*52]==0,
HS[(Y-1)*52]==HS0,
HI[(Y-1)*52]==HI0,
HR[(Y-1)*52]==HR0},
{LQ, LMS, LMI, NQS, NQI, NM, AQ, AM, HS, HI, HR},
{t,(Y-1)*52,Y*52}];

Do[AppendTo[ThingL1,{k,LQ[k]/.soln[[1]]}],{k,(Y-1)*52+1,Y*52}];
Do[AppendTo[ThingL2,{k,LMS[k]/.soln[[1]]}],{k,(Y-1)*52+1,Y*52}];
Do[AppendTo[ThingL3,{k,LMI[k]/.soln[[1]]}],{k,(Y-1)*52+1,Y*52}];
Do[AppendTo[ThingN1,{k,NQS[k]/.soln[[1]]}],{k,(Y-1)*52+1,Y*52}];
Do[AppendTo[ThingN3,{k,NQI[k]/.soln[[1]]}],{k,(Y-1)*52+1,Y*52}];
Do[AppendTo[ThingN2,{k,NM[k]/.soln[[1]]}],{k,(Y-1)*52+1,Y*52}];
Do[AppendTo[ThingA1,{k,AQ[k]/.soln[[1]]}],{k,(Y-1)*52+1,Y*52}];
Do[AppendTo[ThingA2,{k,AM[k]/.soln[[1]]}],{k,(Y-1)*52+1,Y*52}];
Do[AppendTo[ThingH1,{k,HS[k]/.soln[[1]]}],{k,(Y-1)*52+1,Y*52}];
Do[AppendTo[ThingH2,{k,HI[k]/.soln[[1]]}],{k,(Y-1)*52+1,Y*52}];
Do[AppendTo[ThingH3,{k,HR[k]/.soln[[1]]}],{k,(Y-1)*52+1,Y*52}];
Do[AppendTo[AnotherThing,{k,NM[k]/.soln[[1]], HS[k]/.soln[[1]], HI[k]/.soln[[1]], HR[k]/.soln[[1]], LMS[k]/.soln[[1]], LMI[k]/.soln[[1]]}],{k,(Y-1)*52+1,Y*52}];

LQend=LQ[Y*52]/.soln;
LMSend=LMS[Y*52]/.soln;
LMIend=LMI[Y*52]/.soln;
NQSend=NQS[Y*52]/.soln;
NQIend=NQI[Y*52]/.soln;
NMend=NM[Y*52]/.soln;
AQend=AQ[Y*52]/.soln;
AMend=AM[Y*52]/.soln;
HSend=HS[Y*52]/.soln;
HIend=HI[Y*52]/.soln;
HRend=HR[Y*52]/.soln;

L0=egg*AMend[[1]];
NS0=LMSend[[1]];
NI0=LMIend[[1]];
A0=NMend[[1]];
HS0=HSend[[1]];
HI0=HIend[[1]];
HR0=HRend[[1]];

LQ=.; LMS=.; LMI=.;NQS=.;NQI=.; NM=.; AQ=.; AM=.; HS=.; HI=.; HR=.;
,{Y, 1, Ymax}] ;
Print[LMS[52*Ymax]/.soln  [[1]],", ", LMI[52*Ymax]/.soln  [[1]]];
Print[NM[52*Ymax]/.soln  [[1]]];
Print[AM[52*Ymax]/.soln [[1]]];
Print[HS[52*Ymax]/.soln [[1]], ", ", HI[52*Ymax]/.soln [[1]], ", ", HR[52*Ymax]/.soln [[1]]];

ListPlot[{ThingL1, ThingL2, ThingL3},Joined->True, PlotRange-> All]
ListPlot[{ThingN1, ThingN2, ThingN3},Joined->True, PlotRange-> All]
ListPlot[{ThingA1, ThingA2},Joined->True, PlotRange-> All]
ListPlot[{ThingH1, ThingH2, ThingH3},Joined->True, PlotRange-> All]

If[host≠2, 1,Part[groups, 8, habitat]]

prnt=ThingL3;
Print[prnt]
Export["thingy.xls",prnt,"XLS"]