Forum

VBA result in cell ...
 
Notifications
Clear all

VBA result in cell instead of pop up

11 Posts
3 Users
0 Reactions
110 Views
(@padim)
Posts: 5
Active Member
Topic starter
 

Hi,
I posted for the first time yesterday before reading the rules, and I included the code directly in the post. Sorry for my blunder.  I repost according to the rules.
I used ChatGPT (I don't know to code).

I want to search in a workbook composed of a Search page with 2 cells for Start & End dates and a Search button, and several other pages with calendars of diponibilities for guides. Each tab (page) is named after a guide. I colored in yellow each cell when the guide is available.
I want to search between the 2 dates, the cells that are all yellow, meaning the guide is available for the whole period, not only a part of it.
I got a code that gives the tab's names even if only some of the days are free, and it gives it in a pop up window.
Can anyone please correct the code to make sure that all the days included in the result are actually free, and not only some of them, and have the result in the cell F2 of the first page (next to the Search button).

I attached my file for the code.

Thank you very much for your help.

 
Posted : 31/08/2023 6:04 am
(@keebellah)
Posts: 373
Reputable Member
 

Hi, you're one of the many examples that show that GPT is going to cause many issues with would-be programmers.

You find a code that looks lke it does what you want but the user lacks the knowledge to read and understand what the coderealy does.

In fouy serach sheet you mark a cell in RED under a language, but how do you know which language is the one to mark.

The result now is Guide 1 found and then nothing more.

YOU do not know how to code but you also do NOT explain what you want to achieve.

Please be more explicit and please, also tell us which version of Excel you're using

 
Posted : 01/09/2023 2:45 am
(@debaser)
Posts: 837
Member Moderator
 

Try the attached version.

 
Posted : 01/09/2023 5:34 am
(@padim)
Posts: 5
Active Member
Topic starter
 

Dear Velouria,
Thank you very much for your help. It does work sometimes but not always.
For exemple: I search 01-05/12/23, I get No guides available for the specified date range although Guide1, Guide 2 & Guide 8 have all theses cells in yellow.
But if I search 02-05/12/23, it works.
Any idea why this anomaly?
Again, thank you so much for your help.
P.S. I promised I will compare the code with what I had that did ot work to learn 🙂 

 
Posted : 01/09/2023 6:27 am
(@padim)
Posts: 5
Active Member
Topic starter
 

Dear Hans,
Thank you for your help. I am using Excel 2016.
Sorry if I did not explain enough. The languages (red cells on the front page) are not relevant, the search is on the yellow cells into the other pages of the workbook. These cells show when a guide is available and this is the expected result.

 
Posted : 01/09/2023 6:32 am
(@debaser)
Posts: 837
Member Moderator
 

Ahh, I had overlooked the fact that your month header cells are also dates (the first of each month) so it is matching those if you use the first of a month and they are not yellow.

 

Try this version.

 
Posted : 01/09/2023 7:24 am
(@padim)
Posts: 5
Active Member
Topic starter
 

Dear Velouria,
You're great, it works perfectly, thank you so much.
I do not want to abuse, but I have another request. This is not too important, just for the beauty of it. Is it possible to make the result (Guide 1, Guide 2...) as links to the corresponding page?

 
Posted : 01/09/2023 8:12 am
(@debaser)
Posts: 837
Member Moderator
 

Not with the current setup because you can't have multiple hyperlinks in one cell. You'd have to separate the results into multiple cells, then hyperlink them.

 
Posted : 01/09/2023 9:59 am
(@padim)
Posts: 5
Active Member
Topic starter
 

Alright, that was not important anyway.
Thanks again for your precious help.

 
Posted : 01/09/2023 10:34 am
(@keebellah)
Posts: 373
Reputable Member
 

Just for fun, not a hyper link but it works, try this

 

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("F2")) Is Nothing And InStrRev(Target.Text, "Guide") > 0 Then
Dim pos1 As Integer, pos2 As Integer, X As Integer, Y As Integer
Dim msgText As Variant, gArr() As Variant
pos2 = 1: Y = 0: msgText = ""
For X = pos1 To Len(Target.Text)
pos1 = InStr(pos1 + 1, Target.Text, "Guide ")
If pos1 = 0 Then Exit For
pos2 = InStr(pos1 + 1, Target.Text, "Guide ")
If pos2 = 0 Then
Y = Y + 1
msgText = msgText & Y & ". " & Right(Target.Text, Len(Target.Text) - (pos1 - 1))
ReDim Preserve gArr(1 To Y)
gArr(Y) = Right(Target.Text, Len(Target.Text) - (pos1 - 1))
Else
Y = Y + 1
msgText = msgText & Y & ". " & Mid(Target.Text, pos1, (pos2 - pos1) - 2)
ReDim Preserve gArr(1 To Y)
gArr(Y) = Mid(Target.Text, pos1, (pos2 - pos1) - 2)
End If
If pos2 = 0 Then Exit For
msgText = msgText & IIf(Y Mod 3 = 0, Chr(10), Chr(9))
Next X
X = Application.InputBox(msgText, "Enter # 1 - " & Y, 1, Type:=1)
If Val(X) > 0 And Val(X) <= Y Then
Worksheets(gArr(X)).Activate
End If

Cancel = True
End If
End Sub

[code]

 

Place this code in the same worksheet and right click F2 to activate

 
Posted : 02/09/2023 2:55 am
(@keebellah)
Posts: 373
Reputable Member
 

I integrated the code here, just to make it easier

Remember, right-click cell F2

 
Posted : 02/09/2023 4:28 am
Share: