Solved

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

Posted on 2014-09-30
4
58 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 26

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

730 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