Hi magicians,
I'm having issues with an IF VBA script.
I have sheets in a workbook that either contain a value in M3 or L3 - it can never be both.
If a sheet has a value in M3 or L3 of above 0.01, I want to copy & paste particular data.
I've got the below code that isn't working for me where if the value in M3 is less than 0.01, it still copies & pastes the data. However, if I remove the second IF looking at L3 and re-run it, it correctly doesn't pick up less than 0.01 when looking at sheets where it has figures in M3.
Not sure that you can have an IF within an IF like the below or am missing something obvious......any help greatly appreciated!
I'm having issues with an IF VBA script.
I have sheets in a workbook that either contain a value in M3 or L3 - it can never be both.
If a sheet has a value in M3 or L3 of above 0.01, I want to copy & paste particular data.
I've got the below code that isn't working for me where if the value in M3 is less than 0.01, it still copies & pastes the data. However, if I remove the second IF looking at L3 and re-run it, it correctly doesn't pick up less than 0.01 when looking at sheets where it has figures in M3.
Not sure that you can have an IF within an IF like the below or am missing something obvious......any help greatly appreciated!
VBA Code:
If ws.Range("M3").Value >= 0.01 Then
lrow = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
'copy & paste data
With wsDestination
ws.Range("A7:A" & lrow).Copy Destination:=.Range("B" & .Rows.Count).End(xlUp).Offset(1)
ws.Range("B7:B" & lrow).Copy Destination:=.Range("C" & .Rows.Count).End(xlUp).Offset(1)
ws.Range("L7:L" & lrow).Copy Destination:=.Range("E" & .Rows.Count).End(xlUp).Offset(1)
End With
Else
If ws.Range("L3").Value >= 0.01 Then
lrow = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
'copy & paste data
With wsDestination
ws.Range("A7:A" & lrow).Copy Destination:=.Range("B" & .Rows.Count).End(xlUp).Offset(1)
ws.Range("B7:B" & lrow).Copy Destination:=.Range("C" & .Rows.Count).End(xlUp).Offset(1)
ws.Range("L7:L" & lrow).Copy Destination:=.Range("E" & .Rows.Count).End(xlUp).Offset(1)
End With
End If
End If