How to copy excluding one particular column

GirishDhruva

Active Member
Joined
Mar 26, 2019
Messages
308
Hi Everyone,
Here i am trying to copy data from one sheet to another, where i need to exclude one particular column from copy sheet

Like :
Think i have 2 sheets( with names as "Combined","HSR") from HSR i need to copy all the data to Combined sheet excluding column "D" values

Rich (BB code):
Worksheets("HSR").Select
lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
lr2 = Sheets("Combined").Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
Range("A2:C" & lr).Copy Sheets("Combined").Range("A" & lr2 + 1)
Range("E2:AX" & lr).Copy Sheets("Combined").Range("D" & lr2 + 1)

As you can see the solution but instead of "AX" can we give the range dynamically as my columns might increase or decrease

Thank you in advance
Dhruv
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
If row1 always has headers, for example, this might do the trick:

Code:
Sub LastColumnInOneRow()
'Find the last used column in a Row: row 1 in this example
    Dim LastCol As Integer
    With ActiveSheet
        LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
    End Withl
End Sub

You could incorporate the concept into your routine.
 
Last edited:
Upvote 0
Its throwing me a run time error 1004 if i use the below code
Code:
Sub ranges()
    Worksheets("HSR").Select
    lastColumn = Cells(1, Columns.Count).End(xlToLeft).Column
    lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
    lr2 = Sheets("Combined").Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
    LastCol = Sheets("HSR").Cells(1, Columns.Count).End(xlToLeft).Column
    Range("A2:C" & lr).Copy Sheets("Combined").Range("A" & lr2 + 1)
    Range("E2:LastCol" & lr).Copy Sheets("Combined").Range("D" & lr2 + 1)
End Sub
 
Upvote 0
I have tried with the below code also but its throwing me Error code 1004 Method Range of Object _Global Failed

Code:
Sub ranges()
Dim ws As Worksheet
Dim ColumnLetter As Variant
    Set ws = Sheets("HSR")
    Worksheets("HSR").Select
    lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
    lr2 = Sheets("Combined").Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
    ColumnLetter = Split(ws.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Cells.Address(1, 0), "$")(0)
    Range("A2:C" & lr).Copy Sheets("Combined").Range("A" & lr2 + 1)
    Range("E2:ColumnLetter" & lr).Copy Sheets("Combined").Range("D" & lr2 + 1)
End Sub
Could any one suggest me what changes i should make
 
Last edited:
Upvote 0
Why not simply copy all the columns to the new sheet and then delete Column D from that sheet afterwards?
 
Upvote 0
Already in my Combined sheet i would be having some data which i need for further use but from sheet "HSR" column D is an extra column which is not required.
As i neglect/i dont need to copy the column D from sheet "HSR" then the columns would be matched in Combined sheets , if i don't then one extra column would be their in Combined
 
Last edited:
Upvote 0
I got the solution as i required
Code:
Sub ranges()
Dim ws As Worksheet
Dim ColumnLetter As Variant
    Set ws = Sheets("HSR")
    Worksheets("HSR").Select
    lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
    lr2 = Sheets("Combined").Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
    ColumnLetter = Split(ws.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Cells.Address(1, 0), "$")(0)
    Range("A2:C" & lr).Copy Sheets("Combined").Range("A" & lr2 + 1)
    Range("E2:"& ColumnLetter & lr).Copy Sheets("Combined").Range("D" & lr2 + 1)
End Sub
Thanks friends for your help and suggestions
Dhruv
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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