|
-
Oct 29th, 2008, 03:12 PM
#1
Thread Starter
Addicted Member
[RESOLVED] HELP determine if a certain cell is merged
I have an application that reads data from tables in excel. The tables have entries which usually take up one line, then the next line is blank and merged across the table, so in order to get to the next entry I advance 2 rows.
The problem arises when entries take up two rows. In this case advancing 2 rows brings you to a blank, merged row. What I want to do is after advancing two rows, determine if that row is merged and if it is advance another row. Is there a way to determine if a certain cell address is part of a larger merged cell?
Thanks,
--Rikki
-
Oct 29th, 2008, 03:48 PM
#2
Re: HELP determine if a certain cell is merged
if not range("C3").mergecells then
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Oct 30th, 2008, 08:03 AM
#3
Thread Starter
Addicted Member
Re: HELP determine if a certain cell is merged
Ah k thanks. Another problem: I'm trying to determine whether "No Activity for this Account" is present in the worksheet so I am using the find method in an if statement as follows:
Code:
If Not oWorkSheet.Cells.Find("No Activity for this Account") = Nothing Then
This works fine if it is not present, but if it is it throws the error "Run-time exception thrown : System.InvalidCastException - Operator '=' is not defined for type 'Range' and 'Nothing'." If I change it to this:
Code:
If Not oWorkSheet.Cells.Find("No Activity for this Account").Equals(nothing) Then
Then it works if it is present, but if it isn't it gives the error "Referenced object has a value of 'Nothing'."
How Can I get this to work all the time?
Thanks,
--Rikki
Last edited by Rikki_UW; Oct 30th, 2008 at 08:06 AM.
-
Oct 30th, 2008, 08:12 AM
#4
Re: HELP determine if a certain cell is merged
I do it this way. Please amend as applicable...
vb Code:
Sub Test()
'Switch off Error
On Error Resume Next
If Not Sheets("Sheet1").Cells.Find(What:="No Activity for this Account", After:=ActiveCell, LookIn _
:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False) Then
MsgBox "Found"
Else
MsgBox "Not Found"
End If
'Switch Error back on
On Error GoTo 0
End Sub
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 30th, 2008, 09:04 AM
#5
Thread Starter
Addicted Member
Re: HELP determine if a certain cell is merged
I can't switch off errors because the method also contains a try...catch statement, and it's giving me a type mismatch error.
-
Oct 30th, 2008, 09:10 AM
#6
Re: HELP determine if a certain cell is merged
You don't have to switch off and on errors as it seems. you can switch it off just before the IF and switch it on after ENDIF. don't use the code that I have given above... that is to show you how I tested it in excel... use your own code between
vb Code:
On Error Resume Next
'your if code
On Error GoTo 0
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 30th, 2008, 09:18 AM
#7
Thread Starter
Addicted Member
Re: HELP determine if a certain cell is merged
I switched it back to my if code. This is what I have:
Code:
On Error Resume Next
If Not Not oWorkSheet.Cells.Find("No Activity for this Account") = Nothing Then
noActivity = oWorkSheet.Cells.Find("No Activity for this Account", nextFind).Row()
End If
On Error GoTo 0
But both the error off and error on lines are underline with the error "Method cannot contain both a 'try' statement and an 'On Error' or 'Resume' statement." Same with the try statement which follows a few lines after errors are switched back on.
Also, which version should I be using? "= nothing" or ".equals(nothing)"?
Last edited by Rikki_UW; Oct 30th, 2008 at 09:52 AM.
-
Oct 30th, 2008, 10:49 AM
#8
Re: HELP determine if a certain cell is merged
Try this, since it is working when the string is found...
If Not oWorkSheet.Cells.Find("No Activity for this Account").Equals(nothing) Then
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 30th, 2008, 10:56 AM
#9
Thread Starter
Addicted Member
Re: HELP determine if a certain cell is merged
Tried that but it gives the error "Referenced object has a value of 'Nothing'." if it is not present.
I'm trying putting them both in separate try catch statements so that one of them will always work.
-
Oct 30th, 2008, 10:58 AM
#10
Re: HELP determine if a certain cell is merged
can you upload your workbook?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 30th, 2008, 11:07 AM
#11
Thread Starter
Addicted Member
Re: HELP determine if a certain cell is merged
That worked, thanks for the help though. If there's a better way to do it though I'm definitely open to suggestions.
--Rikki
-
Oct 30th, 2008, 03:14 PM
#12
Re: [RESOLVED] HELP determine if a certain cell is merged
any object can not = nothing
should be
If Not oWorkSheet.Cells.Find("No Activity for this Account") Is Nothing Then
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Oct 30th, 2008, 04:06 PM
#13
Thread Starter
Addicted Member
Re: [RESOLVED] HELP determine if a certain cell is merged
Ah that works, thanks westconn1.
Sorry koolsid, missed your post. No I can't, too much confidential information.
--Rikki
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|