Solved

Follow on to earlier Excel VBA question

Posted on 2014-10-17
2
105 Views
Last Modified: 2014-10-17
In a different question, a follow on to this :
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_28538139.html
I now need loop through all rows in a worksheet, output cell values in a specified column order based on values in Row 1:
Study	Filo	Mean	Olp	Std Dev	Bell
Sun	9	29.998	77	33.887	G
Mercury	66	30.686	29	37.03	R
Venus	53	993.09	65	643	H
Earth	44	44.099	22	34.06	J
Mars	78	77.94	90	22.796	B

Open in new window

For instance, beginning with row 2, output the cell value of the column with the 'label' of Mean [29.988]
then the cell value of the column of 'Std Dev' [33.887]
then the cell value of the column of 'Study' [Sun]
Then continue processing the remainder of the rows in the worksheet.
At first, it seems to be simple, alas not so much: lookup the value of row [r], column[x] where column heading is [Mean].  Repeat for heading [Std Dev] and then heading [Study], regardless of the column order.
and I have no way of knowing the sheet name,  or even how many columns there are in the sheet, just that the columns have those headings.  I have tried hlookup, but can't seem to get it to work when searching for the heading columns, and I am not convinced that hlookup is the correct function to use.
Hope this is clear, and thanks for looking.
0
Comment
Question by:Program652
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Accepted Solution

by:
slubek earned 500 total points
ID: 40386756
Hi, again :^)

If I understand Your problem correctly, declare three variables:
sStudy, sStdev, sMean as String
Find their values first, then create output in proper order:
    While Cells(iRow, 1) > ""
        sXML = sXML & "<row id=" & Q & iRow & Q & ">"

		For icol = 1 To iColCount - 1
			select CASE Cells(iCaptionRow,icol)
			case "Study"
				sStudy = Trim$(Cells(iRow, icol))
			case "Mean"
				sMean = Trim$(Cells(iRow, icol))
			case "Std Dev"
				sStdDev = Trim$(Cells(iRow, icol))
			end select
		Next

		sXML = sXML & "<Study>" & sStudy & "</Study>"
		sXML = sXML & "<Mean>" & sMean & "</Mean>"
		sXML = sXML & "<Std Dev>" & sStdDev & "</Std Dev>"
		
        sXML = sXML & "</row>"
        iRow = iRow + 1
    Wend

Open in new window

0
 

Author Comment

by:Program652
ID: 40386795
Well, made that look easy... <grin>
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question