Solved

Excel vba to place field name from another worksheet into a different cell/worksheet

Posted on 2014-09-30
4
53 Views
Last Modified: 2016-02-11
Hi Experts,

I have some script that I have copied from textpad and pasted into excel.  I need to update the script incrementally where it says "samp1" below and I need to change the select statement in that script as well.  I have all of the field names pasted in one column in sheet2 of my excel workbook and the script is pasted on sheet1.  See example below:

Sheet 1

samp1.abc
samp1.123
samp1.nowIknow
samp1.sql=select * from "the first name in cell a1 on sheet2"

samp2.abc
samp2.123
samp2.nowIknow
samp2.sql=select * from "the first name in cell a2 on sheet2"

samp3.abc
samp3.123
samp3.nowIknow
samp3.sql=select * from "the first name in cell a3 on sheet2"
0
Comment
Question by:daintysally
  • 2
4 Comments
 
LVL 25

Expert Comment

by:ProfessorJimJam
ID: 40353268
can give more details, perhaps an example file?
0
 
LVL 20

Accepted Solution

by:
ElrondCT earned 500 total points
ID: 40356261
Are you looking for something like this?
Sub OutputLines()
    For i = 1 To 5
        Cells(i * 5, 1).Formula = "samp" & i & ".abc"
        Cells(i * 5 + 1, 1).Formula = "samp" & i & ".123"
        Cells(i * 5 + 2, 1).Formula = "samp" & i & ".nowIknow"
        Cells(i * 5 + 3, 1).Formula = "samp" & i & ".sql=select * from ""the first name in cell a" & i & " on sheet2"""
    Next i
End Sub

Open in new window

0
 

Author Comment

by:daintysally
ID: 40357448
@ElrondCT...yes, that is what I am aiming for
0
 

Author Closing Comment

by:daintysally
ID: 40789734
Thank you, this put me on the right path
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Modern/Metro styled message box and input box that directly can replace MsgBox() and InputBox()in Microsoft Access 2013 and later. Also included is a preconfigured error box to be used in error handling.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now