Define range of columns to copy

fari1

Active Member
Joined
May 29, 2011
Messages
362
hi, below is the part of a code, this line of code copies the entire row and paste in sheet2(i-e wsdst) what i want is that the code to copy range A to Z instead of entire row.

Code:
If Not rngAll Is Nothing Then rngAll.EntireRow.Copy wsDst.Cells(Rows.Count, "B").End(xlUp).Offset(1)
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Untested, but how about?
Rich (BB code):
If Not rngAll Is Nothing Then rngAll.EntireRow.Resize(, 26).Copy wsDst.Cells(Rows.Count, "B").End(xlUp).Offset(1)
 
Upvote 0
rngAll.EntireRow.Resize(, 26).Copy wsDst.Cells(Rows.Count, "B").End(xlUp).Offset(1)


this part of the code, it is highlighting, and giving application defined error
 
Upvote 0
Run this bit of code, just to give you an idea of what I was thinking.
Code:
Range("C5").EntireRow.Resize(, 5).Select
Without knowing more about the context/details of your code I can't really say any more.
 
Upvote 0
just to u give u an idea, this is my complete code

Code:
Sub findTEXT()
    
    Static wsSrc As Worksheet: Set wsSrc = ActiveWorkbook.Sheets("Sheet2")
    Static wsDst As Worksheet: Set wsDst = ActiveWorkbook.Sheets("Sheet3")
    
    Static StartAddress As String
    Dim rngFnd As Range
    Dim rngAll As Range
    Dim allfound As Boolean
    
    Set rngFnd = wsSrc.UsedRange.Find("consolidated")
    If Not rngFnd Is Nothing Then StartAddress = rngFnd.Address
    
    While Not rngFnd Is Nothing And allfound = False
        If RowLen(wsSrc, rngFnd) < 50 And rngAll Is Nothing Then Set rngAll = rngFnd
        Set rngFnd = wsSrc.UsedRange.Find("consolidated", rngFnd)
        If RowLen(wsSrc, rngFnd) < 50 Then
            If rngAll Is Nothing Then Set rngAll = rngFnd
            If Intersect(rngAll, rngFnd) Is Nothing _
            And Intersect(rngAll.EntireRow, rngFnd) Is Nothing _
            Then Set rngAll = Union(rngAll, rngFnd)
        End If
        If rngFnd.Address = StartAddress Then allfound = True
    Wend
If Not rngAll Is Nothing Then rngAll.EntireRow.Copy wsDst.Cells(Rows.Count, "B").End(xlUp).Offset(1)
wsDst.Range("AA" & wsDst.UsedRange.Offset(, 1).Find(what:="*", after:=wsDst.[B1], searchdirection:=xlPrevious).Row + 1).Value = wsSrc.Range("A1").Value
End Sub
Function RowLen(ws As Worksheet, rng As Range) As Long
    
    Dim c As Range
    For Each c In Intersect(rng.EntireRow, ws.UsedRange)
        RowLen = RowLen + Len(c.Text)
    Next c
    
End Function

and this part of the code i want to change to bring the row after resize, so that i may have the blank column A
Code:
If Not rngAll Is Nothing Then rngAll.EntireRow.Copy wsDst.Cells(Rows.Count, "B").End(xlUp).Offset(1)
 
Upvote 0
replace
Code:
rngAll.EntireRow.copy
with

Code:
intersect(rngAll.EntireRow,rngall.worksheet.range("A:Z")).copy
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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