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
Solved

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

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

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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…

790 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