Last Used Range

fari1

Active Member
Joined
May 29, 2011
Messages
362
<b>Sheet2</b><br /><br /><table border="1" cellspacing="0" cellpadding="0" style="font-family:Calibri,Arial; font-size:11pt; background-color:#ffffff; padding-left:2pt; padding-right:2pt; "> <colgroup><col style="font-weight:bold; width:30px; " /><col style="width:145px;" /><col style="width:172px;" /><col style="width:233px;" /></colgroup><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td > </td><td >B</td><td >C</td><td >D</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7359</td><td >CONDENSED CONSOLIDATING STATEMENT OF INCOME </td><td > </td><td > </td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7360</td><td > </td><td > </td><td > </td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7361</td><td > </td><td > </td><td >Nine Months Ended September 30, 2006</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7362</td><td > </td><td > </td><td > </td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7363</td><td > </td><td > </td><td > </td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7364</td><td >In millions of dollars</td><td > </td><td >Citigroup</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7365</td><td > </td><td > </td><td >parent</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7366</td><td > </td><td > </td><td >company</td></tr></table> <br />Excel tables to the web - Excel Jeanie Html 4

i've a line of code, which brings in a cell value after last used range in column A from another sheet with my below piece of code

Code:
wsDst.Range("AA" & Rows.Count).End(xlUp)(2) = wsSrc.Range("A1").Value

while i want to get the value in column A after the last used range from B to onwards columns, meaning in above example the value to be brought in by code in cell A7367.

hope i made my point clear, want help on it urgently:(
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Urgently or not, that is irrelevant since you ask a favour from voluntary helpers.

Try:

Code:
wsDst.Range("AA" & Rows.Count).End(xlUp)(2) = wsSrc.Range("A1").Value
 
Upvote 0
hi, thanks for the help, you posted the code that checks for the last used range and brings in data in A7367? u posted my line of code as it is, didn't change anything
 
Upvote 0
Oops, error.

Code:
wsDst.Range("AA" & wsDst.UsedRange.Offset(, 1).Find(what:="*", after:=wsDst.[B1], searchdirection:=xlPrevious).Row + 1).Value = wsSrc.Range("A1").Value
 
Upvote 0
For me on a test file it works fine, so it must be something in your file.

Please debug using F8, MsgBox, the Immediate Window, removing sheet references, and so on.
 
Upvote 0
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, "A").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
 
Upvote 0
Start a new empty file, fill the appropriate cells (a.o. cell Z1), and consider:

Code:
Sub Wigi()
    
    Range("A" & ActiveSheet.UsedRange.Offset(, 1).Find(what:="*", after:=[B1], searchdirection:=xlPrevious).Row + 1).Value = Range("Z1").Value

End Sub

If has no sheet references so you can then test sheet references as a cause of your error.
 
Upvote 0
its working in new sheet, with my workbook, i'm running this code in wssrc and want the output in wsdst,considering the used values in wsdst, and want the Cell A1 value from wssrc, its not working there, unable to find out

wsDst.Range("A" & wsDst.UsedRange.Offset(, 1).Find(what:="*", after:=[B1], searchdirection:=xlPrevious).Row + 1).Value = wsSrc.Range("A1").Value
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,181
Members
452,893
Latest member
denay

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