Hello everyone,
I have Problems to optimize a VBA routine.
In this routine when the value in the column "Room Number" matches the value I specify, then it moves the data to the specified cells on Sheet 2 of Workbook 2. The Name of this Sheet2 has the same as a the value of the column "Room Number".
In this case I will have a Macro for each "Room Number" since I have to specify what the value of the "Room Number" is in each Macro.
Sub Transferdata()
Dim ws1 As Worksheet, ws2 As Worksheet, i As Long
Dim lastrow As Long
strFirstFile = "X:\47_LGB\Schriftverkehr\4. Nutzer\04_Raumprogramm\WB1.xlsm"
strSecondFile = "X:\47_LGB\Schriftverkehr\4. Nutzer\04_Raumprogramm\WB2.xlsm"
Set wbk1 = Workbooks.Open(strFirstFile)
Set ws1 = wbk1.Sheets("DATA")
Set wbk2 = Workbooks.Open(strSecondFile)
Set ws2 = wbk2.Sheets("00.001")
lastrow = ws1.Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To lastrow
If ws1.Cells(i, 1).Value = "00.001" Then
ws2.Cells(1, 1).Value = ws1.Cells(i, 2).Value
ws2.Cells(1, 2).Value = ws1.Cells(i, 3).Value
End If
Next
ws1.Close SaveChanges:=False
End Sub
Since I have a lot of Rooms, I would like to optimize it like that:
A-Find values in the column "No. of Rooms" in book 1 that match with a Sheetname in book 2. For example the value will be 00.001
B-Selections of cell values in the row where the value "00.001" is found in book 1
C-Select the Sheet in book 2 with the name 00.001 as the active page
D-Copy the data from the cells of book 1 (Step B) into specific cells of the corresponding active sheet (Step C)
I was just wondering if someone could help with the match of cells with Sheetname and on the corresponding sheet .
Thank you for any possible assistance.
Best regards,
Maria.
PD: the data of wb1.ws1 are regularly updated but remains in the same position. "Room Number" never changes. There ar
I have Problems to optimize a VBA routine.
In this routine when the value in the column "Room Number" matches the value I specify, then it moves the data to the specified cells on Sheet 2 of Workbook 2. The Name of this Sheet2 has the same as a the value of the column "Room Number".
In this case I will have a Macro for each "Room Number" since I have to specify what the value of the "Room Number" is in each Macro.
Sub Transferdata()
Dim ws1 As Worksheet, ws2 As Worksheet, i As Long
Dim lastrow As Long
strFirstFile = "X:\47_LGB\Schriftverkehr\4. Nutzer\04_Raumprogramm\WB1.xlsm"
strSecondFile = "X:\47_LGB\Schriftverkehr\4. Nutzer\04_Raumprogramm\WB2.xlsm"
Set wbk1 = Workbooks.Open(strFirstFile)
Set ws1 = wbk1.Sheets("DATA")
Set wbk2 = Workbooks.Open(strSecondFile)
Set ws2 = wbk2.Sheets("00.001")
lastrow = ws1.Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To lastrow
If ws1.Cells(i, 1).Value = "00.001" Then
ws2.Cells(1, 1).Value = ws1.Cells(i, 2).Value
ws2.Cells(1, 2).Value = ws1.Cells(i, 3).Value
End If
Next
ws1.Close SaveChanges:=False
End Sub
Since I have a lot of Rooms, I would like to optimize it like that:
A-Find values in the column "No. of Rooms" in book 1 that match with a Sheetname in book 2. For example the value will be 00.001
B-Selections of cell values in the row where the value "00.001" is found in book 1
C-Select the Sheet in book 2 with the name 00.001 as the active page
D-Copy the data from the cells of book 1 (Step B) into specific cells of the corresponding active sheet (Step C)
I was just wondering if someone could help with the match of cells with Sheetname and on the corresponding sheet .
Thank you for any possible assistance.
Best regards,
Maria.
PD: the data of wb1.ws1 are regularly updated but remains in the same position. "Room Number" never changes. There ar