Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-21-2022, 04:48 PM
eduzs eduzs is offline Simplest way to get row and column number? Windows 10 Simplest way to get row and column number? Office 2019
Expert
Simplest way to get row and column number?
 
Join Date: May 2017
Posts: 260
eduzs is on a distinguished road
Default Simplest way to get row and column number?

Is there a simpler way to get row and column numbers from the current selected cell in a word table with horizontally or vertically merged cells?
I need to retrieve the text of the cell above current selected cell.
This code does not works (works only if I add 1 to column index) cause there's merged cells in the selected row.
Code:
selection.tables(1).Cell(selection.Cells(1).rowindex-1,selection.Cells(1).columnindex).Range.text
Thanks
Reply With Quote
  #2  
Old 06-21-2022, 05:42 PM
macropod's Avatar
macropod macropod is offline Simplest way to get row and column number? Windows 10 Simplest way to get row and column number? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

For current cell addresses, look in the 'Sticky' thread at the top of this forum...

Finding the adjacent cell(s) requires looping forward/backward, as appropriate.

With horizontally merged cells, there may be more than one cell above or below.

With vertically merged cells, you may have to loop through multiple rows to find all those adjacent or to find the one below.

And, where you're dealing with both, you might have to deal with horizontally-merged cells above/below/beside vertical ones.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-21-2022, 06:02 PM
eduzs eduzs is offline Simplest way to get row and column number? Windows 10 Simplest way to get row and column number? Office 2019
Expert
Simplest way to get row and column number?
 
Join Date: May 2017
Posts: 260
eduzs is on a distinguished road
Default

Apparently it will be too complex, I give up, as it will not be something essential.
Thanks!
Reply With Quote
  #4  
Old 06-22-2022, 04:04 PM
Guessed's Avatar
Guessed Guessed is offline Simplest way to get row and column number? Windows 10 Simplest way to get row and column number? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

If you use the selection object it isn't too complex.
Code:
Sub GetUp()
  Dim aCell As Cell, aRng As Range
  Set aRng = Selection.Range
  Selection.Range.Cells(1).Select
  Selection.MoveUp
  If Selection.Range.Cells.Count = 1 Then
    Debug.Print Selection.Range.Cells(1).Range.Text
  Else
    Debug.Print "No cells immediately above selection"
  End If
  aRng.Select  'restore selection
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 06-23-2022, 03:04 AM
eduzs eduzs is offline Simplest way to get row and column number? Windows 10 Simplest way to get row and column number? Office 2019
Expert
Simplest way to get row and column number?
 
Join Date: May 2017
Posts: 260
eduzs is on a distinguished road
Default

Works fine.
Many thanks.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simplest way to get row and column number? Count number of Ms between Hs in a column Marcia Excel 6 05-12-2020 06:21 PM
Want a quotient using a constant to show up in column c each time a number is added to column b fibbermcghee Excel 2 12-09-2014 05:48 PM
Simplest way to get row and column number? Formatting numbers in number column MS baby Project 1 06-03-2014 02:43 PM
Simplest way to get row and column number? What's The Best & Simplest Software Program To Backing Up Outlook 2010 highbids Outlook 1 08-23-2010 04:10 PM
Simplest way to get row and column number? Last Number in a Column paulrm906 Excel 1 12-05-2008 07:51 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:57 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft