Dweller95

New Member
Joined
Nov 11, 2021
Messages
10
Office Version
  1. 2016
Platform
  1. Windows
Hi everyone,

I'm trying to copy the range of the second table (green background), however I can only get it to copy the blue background table. I was trying to set it up so the "LastRow" was set to the row that the string "Total" is located. Which worked for my first function addSetB, which grabs the blue table if that option was selected.

I'm not able to get this working to copy over the green table and wondering how I should change my function around or how do I go about accomplishing this.

Appreciate any feedback and anyone who takes some time to try and help me out.

1636637289067-png.50969


Here is the code I used to copy SetB (Blue Background) which functions correctly.
VBA Code:
' ADD Data from SetB (Blue Background) to 'DATA' Sheet
Sub addSetB()
    
    Dim LastRow As Integer
    LastRow = Cells.Find(What:="Total", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Range("L3:Q" & LastRow).Copy
    
    Sheets("DATA").Activate
    Cells(Range("A" & rows.Count).End(xlUp).Row + 1, 1).PasteSpecial xlPasteValues
          
End Sub

Here is my attempt at copying SetC (Green Background) which is not working properly at all.
VBA Code:
' ADD Data from SetC (Green Background) to 'DATA' Sheet
Sub addSetC()
    
    Dim LastRow As Integer
    Dim StartRow As Integer
    StartRow = Cells.Find(What:="Total", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    LastRow = Cells.Find(What:="Total", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    
    Range("L" & StartRow & ":Q" & LastRow).Copy
    
    Sheets("DATA").Activate
  
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Here is my attempt at copying SetC (Green Background) which is not working properly at all.
VBA Code:
' ADD Data from SetC (Green Background) to 'DATA' Sheet
Sub addSetC()
   
    Dim LastRow As Integer
    Dim StartRow As Integer
    StartRow = Cells.Find(What:="Total", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    LastRow = Cells.Find(What:="Total", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
   
    Range("L" & StartRow & ":Q" & LastRow).Copy
   
    Sheets("DATA").Activate
 Cells(Range("A" & rows.Count).End(xlUp).Row + 1, 1).PasteSpecial xlPasteValues
End Sub
Sub addSetC() did not contain the paste in the actual post, so fixed here.
 
Upvote 0

Forum statistics

Threads
1,222,069
Messages
6,163,737
Members
451,854
Latest member
Tiffany Smith

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top