Solved

Follow on to earlier Excel VBA question

Posted on 2014-10-17
2
104 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

756 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