ChrisRamsden
New Member
- Joined
- Sep 26, 2018
- Messages
- 24
Hi again everyone,
Got another problem i would love some help with, and after having so much success here recently i wanted to challenge you all again. I am currently writing a macro to scan through multiple files looking for the sheet name which matches a cell reference in another workbook (where the macro is triggered from.) The problem i am having is i can't get it to find the sheet, as i believe the issue is the reference cell.
The reference cell is D9 which contains the value 01/01/18 but is formatted to appear as Jan. I built this into my code but i can't get it working. I think the rest of the macro will work fine once it is able to find the correct sheet.
Any help would be greatly appreciated.
Thank you,
Chris
Got another problem i would love some help with, and after having so much success here recently i wanted to challenge you all again. I am currently writing a macro to scan through multiple files looking for the sheet name which matches a cell reference in another workbook (where the macro is triggered from.) The problem i am having is i can't get it to find the sheet, as i believe the issue is the reference cell.
The reference cell is D9 which contains the value 01/01/18 but is formatted to appear as Jan. I built this into my code but i can't get it working. I think the rest of the macro will work fine once it is able to find the correct sheet.
Code:
Dim Wb2 As Workbook
Dim Wks As Worksheet, sh As Worksheet, Dsh As Worksheet
Dim Rng As Range, c As Range
Dim Rw As Range
Dim i As Long
Dim toprow As Long
'Stop background controls to improve macro efficiency
Application.DisplayAlerts = False
Application.ScreenUpdating = False
'Set perameters
mainpath = Range("b17").Value
Set mainfile = Workbooks("PSR Suite 2018 - Test 2.xlsm")
Set Dsh = mainfile.Sheets("Disputes Log v2")
Set Wks = mainfile.Sheets("Update")
Set Rng = Wks.Range("D9")
month = Format(Rng.Value, "MMM")
'Populate Disputes Log v2
'Open file selection panel to select files
With Application.FileDialog(3)
.InitialFileName = "Filepath here"
.Show
For Each myFile In .SelectedItems
Set Wb2 = Workbooks.Open(myFile)
'From each file select data to copy & paste into spreadsheet.
For Each sh In Sheets
If sh.Name = month Then
variable = Cells(Rows.Count, 3).End(xlUp).Row
Rows("2:" & variable).Copy
mainfile.Sheets("Disputes Log v2").Activate
Range("C" & Rows.Count).End(xlUp).Offset(1).Select
Selection.Offset(0, -2).PasteSpecial PasteSpecial:=PasteValue
End If
Next sh
Wb2.Close False
Next myFile
'Add Month and Year to data
toprow = 1 'Change this to whatever the top row is
For i = toprow To Cells(Rows.Count, 1).End(xlUp).Row
If Cells(i, 3) > "" And Cells(i, 10) = "" Then
Wks.Range("D9").Copy
Cells(i, 10).PasteSpecial PasteSpecial:=PasteValue
Wks.Range("D10").Copy
Cells(i, 11).PasteSpecial PasteSpecial:=PasteValue
End If
Next i
'Reset background controls
Application.DisplayAlerts = True
Application.ScreenUpdating = True
'Report out the Macro has finished
MsgBox "Macro Complete"
End With
End Sub
Any help would be greatly appreciated.
Thank you,
Chris
Last edited: