Hi Gloria,
I was looking for someone to help me with my VBA code that I provided above for me to select multiple specific ranges with last column and row for each multiple range. Can you please help with that since I don't want to use a formula?
@ZH_M
Hi
Find in the link a file with the VBA solution as per your requirements
Notes:
1- Sheets("Destination") refers to Sheets("Sheet1") on your original code
2- On the file, there are 2 VBA solutions options
Option 1
Using a regular macro module with a Command Button.
*******************************************************************************************************
Private Sub CommandButton1_Click()
Dim DateRange As Range, lastColumn As Long
Dim firstRange As Range, secondRange As Range
With Sheets("Source")
lastColumn = .UsedRange.Columns.Count
Set DateRange = .Range("B1").Resize(1, lastColumn - 1)
Set firstRange = .Range("A10").Resize(5, lastColumn)
Set secondRange = .Range("A19").Resize(4, lastColumn)
End With
Application.ScreenUpdating = False
Sheets("Destination").Cells.Clear ''' To Delete "Old data"
Sheets("Destination").Range("A1").Value = "Row Label"
DateRange.Copy Sheets("Destination").Range("B1") ''' To Paste Dates
firstRange.Copy Sheets("Destination").Range("A2") ''' To paste first group values
secondRange.Copy Sheets("Destination").Range("A7") ''' To paste second group values
Sheets("Destination").Columns.AutoFit ''' To tide up output data.
Application.ScreenUpdating = True
MsgBox "Job Done"
End Sub
************************************************************************************************
Option 2
Using the change event of the Source sheet.
In this case, the macro will run automatically once you deactivate (leave) the "Source" sheet to select any other sheet in the workbook. So when you finish the update on "Source" sheet, once you select the "Destination" sheet it will update instantly
*************************************************************************************************
Private Sub Worksheet_Deactivate()
Dim DateRange As Range, lastColumn As Long
Dim firstRange As Range, secondRange As Range
With Me
lastColumn = .UsedRange.Columns.Count
Set DateRange = .Range("B1").Resize(1, lastColumn - 1)
Set firstRange = .Range("A10").Resize(5, lastColumn)
Set secondRange = .Range("A19").Resize(4, lastColumn)
End With
Application.ScreenUpdating = False
Sheets("Destination").Cells.Clear ''' To Delete "Old data"
Sheets("Destination").Range("A1").Value = "Row Label"
DateRange.Copy Sheets("Destination").Range("B1") ''' To Paste Dates
firstRange.Copy Sheets("Destination").Range("A2") ''' To paste first group values
secondRange.Copy Sheets("Destination").Range("A7") ''' To paste second group values
Sheets("Destination").Columns.AutoFit ''' To tide up output data.
Application.ScreenUpdating = True
MsgBox "Destination sheet, Updated successfully"
End Sub
***************************************************************************************************
Here is the link to the workbook.
https://1drv.ms/x/s!AjGRD1TlwpAGmGMqYVxOEpVdNGRS?e=goC84C
Do let me know if you need more help
On the other hand,
If the answer helped you.
Please, consider marking this thread as answered.
It would help others in the community with similar questions or problems.
Thank you in advance
Regards
Jeovany