Hi All,
I have a VBA code to look in column G to find the first non blank cell and return the value in the same row on column C and copy and paste the result to another workbook
Here is the code which works ok
However if there is a Value already in the first cell "G16" the code doesn't return the value i want which should be "C16", It seems to continue until it finds the next blank cell.
I have tried playing around with the code but to no avail, please see below the code i have been trying but this code returns a blank.
I'm new enough to VBA so not sure where i am going wrong, any help is greatly appreciated.
Regards,
Simon
I have a VBA code to look in column G to find the first non blank cell and return the value in the same row on column C and copy and paste the result to another workbook
Here is the code which works ok
Code:
'Now, copy what you want from InputFile:
InputFile.Sheets("Customer Timesheet").Activate
InputFile.Sheets("Customer Timesheet").Range("G16").End(xlDown).Offset(0, -4).Copy
'Now, paste to OutputFile worksheet:
OutputFile.Sheets("Sheet1").Activate
OutputFile.Sheets("Sheet1").Range("H" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
However if there is a Value already in the first cell "G16" the code doesn't return the value i want which should be "C16", It seems to continue until it finds the next blank cell.
I have tried playing around with the code but to no avail, please see below the code i have been trying but this code returns a blank.
Code:
'Now, copy what you want from InputFile:
InputFile.Sheets("Customer Timesheet").Activate
If Range("G16") <> "" Then
Range("G16").Offset(0, -4).Copy
Else
InputFile.Sheets("Customer Timesheet").Range("G16").End(xlDown).Offset(0, -4).Copy
'Now, paste to OutputFile worksheet:
OutputFile.Sheets("Sheet1").Activate
OutputFile.Sheets("Sheet1").Range("H" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
End If
I'm new enough to VBA so not sure where i am going wrong, any help is greatly appreciated.
Regards,
Simon