Help with If statement based on cell value of Active Sheet

kt_mr_excel

New Member
Joined
Sep 24, 2021
Messages
15
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I'm obviously very new to VBA in Access and need some help with a very simple If statement based on the value of a specified cell in the active Excel worksheet. My many attempts have included every type of declaration I could find in online examples and many different range expressions but always result in an "error 91 - Object variable or With block variable not set". I also tried using a With block without any luck. Here's my simple sub - I thought that this approach would not require declaration of any variables, but obviously I thought wrong. Any help would be appreciated. (Note: Excel 16.0 Object Library is referenced)

Sub MySub()
If Excel.Application.ActiveSheet.Range("A1").Value = "String to match" Then
MsgBox "Message string"
End If
End Sub
 
Ahh, so I wasted all my time here providing you with the same answer that you already got elsewhere and you didn't bother to announce that you had cross posted.
Thanks. Won't happen again.
 
Upvote 0

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
My apologies if you feel your time was wasted, but I was merely trying to get an answer to the core question of how to set the wb variable to the open wb without a file path.
 
Upvote 0
My apologies if you feel your time was wasted, but I was merely trying to get an answer to the core question of how to set the wb variable to the open wb without a file path.

There are rules about cross-posting which you agreed to follow when you registered here at MrExcel.

Please read this article on the etiquette of cross-posting

 
Upvote 0
Not often people admit to crossposting without notification themselves :)
 
Upvote 0
If it matters, I've never posted or joined any other forums. I just googled for setting the wb object to the open wb and came across a suggestion that worked. Just thought sharing it may help another struggling newbie.
 
Upvote 0
Upvote 0
If it matters, I've never posted or joined any other forums. I just googled for setting the wb object to the open wb and came across a suggestion that worked. Just thought sharing it may help another struggling newbie.
Yes, that matters, a lot. That is not crossposting. At least not to me, so well done for finding a solution.?
 
Upvote 0
If you didn't cross post you should have said so when I wrongly accused you of it. For that, I apologize.
In fairness, "I found a solution..." and posting the link would have been perceived differently than "I received another solution...) and not doing so.
Perhaps all those posts on that subject should be deleted.
 
Upvote 0

Forum statistics

Threads
1,224,986
Messages
6,182,154
Members
453,093
Latest member
Soffy

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