ActiveCell.value does not display anything

pwr1965

New Member
Joined
Aug 25, 2022
Messages
9
Office Version
  1. 365
Platform
  1. Windows
I have a number of values, originating from a given worksheet, that need to be displayed on another worksheet. This works great for most values with the following code:

Sheets("Invulblad").Select
Range("M4").Select
Selection.End(xlDown).Select
Sheets(Sheets.Count).Range("B13") = ActiveCell.Value

Here's the problem: it does not work if the active cell contains a formula. On the source worksheet I can see the formula result, but VBA does not copy the resulting value to its destination. Ideas anyone?
 
Hi Joe4,
Thanks a million, this makes my code a lot leaner. Alas, it did not solve my initial problem: all source cells containing formulas result in empty destination cells..
My guess is your code is working exactly as it should, you just don't realize that you have a formula returning a blank cell in there somewhere.

Try adding this code above what your currently have, and see what it returns:
VBA Code:
Dim r as Long
r = Sheets("Invulblad").Range("M4").End(xlDown).Row
MsgBox "Returning value from row " & r
Then verify what is in column M of that row on your "Invulblad" sheet.
That is what is your code is returning.
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Yes, that I have.

In that case using
VBA Code:
Range("M4").Select
   Selection.End(xlDown).Select
Will take you the very last row in col M that has a formula & it's probably returning ""
You're totally right. Thing is, I need the formulas there to do the VLOOKUP thing. Is there a VBA equivalent for this function?
 
Upvote 0
My guess is your code is working exactly as it should, you just don't realize that you have a formula returning a blank cell in there somewhere.

Try adding this code above what your currently have, and see what it returns:
VBA Code:
Dim r as Long
r = Sheets("Invulblad").Range("M4").End(xlDown).Row
MsgBox "Returning value from row " & r
Then verify what is in column M of that row on your "Invulblad" sheet.
That is what is your code is returning.
You're right (Fluff already posted something similar). The thing is: based on an article code that is input on "Invulblad", a VLOOKUP formula fills several other cells in that particular row with stuff like a job description and a price. This formula is copied down in column M, so it works for each new row. Now, thanks to you guys, I understand how this throws a spanner in the works of my VBA code. Is there a way around this?
 
Upvote 0
How about
VBA Code:
   Dim Fnd As Range
   With Sheets("Invulblad")
      Set Fnd = .Range("M4:M10000").Find("*", , xlValues, , xlByRows, xlPrevious, , False)
      If Not Fnd Is Nothing Then
         Sheets(Sheets.Count).Range("B13").Value = Fnd.Value
      End If
   End With

Edited to show correction mentioned below
 
Last edited:
Upvote 0
Solution
How about
VBA Code:
   Dim Fnd As Range
   With Sheets("Invulblad")
      Set Fnd = .Range("M4:M10000").Find("*", , xlValues, , xlByRows, xlPrevious, , False)
      If Fnd Is Not Nothing Then
         Sheets(Sheets.Count).Range("B13").Value = Fnd.Value
      End If
   End With
Hi Fluff,
This returns a compiler error; sit marks 'Nothing' as invalid.
 
Upvote 0
Oops, that line should be
VBA Code:
      If Not Fnd Is Nothing Then
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,730
Members
448,987
Latest member
marion_davis

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