Solved

Shorten VBA to one statement instead of three?

Posted on 2014-10-08
6
95 Views
Last Modified: 2014-10-08
Is there a way to combine Ln2 thru 4?  I do not believe I have to select the sheet tab each time as long as it is active.  I just want to put the value collected for Ln1 in a specific cell location on a specific sheet tab.

    MatlDescValue = session.findbyid("wnd[0]/usr/tabsTABSPR1/tabpSP02/ssubTABFRA1:SAPLMGMM:2004/subSUB1:SAPLMGD1:1002/txtMAKT-MAKTX").Text 'Matl Description
    Sheets("BasicData1").Select
    Range("B5").Select
    ActiveCell.FormulaR1C1 = MatlDescValue

Open in new window

0
Comment
Question by:RWayneH
  • 4
  • 2
6 Comments
 
LVL 25

Expert Comment

by:ProfessorJimJam
ID: 40368382
Sheets("BasicData1").Range("B5").Select
0
 
LVL 25

Expert Comment

by:ProfessorJimJam
ID: 40368385
     MatlDescValue = session.findbyid("wnd[0]/usr/tabsTABSPR1/tabpSP02/ssubTABFRA1:SAPLMGMM:2004/subSUB1:SAPLMGD1:1002/txtMAKT-MAKTX").Text 'Matl Description
    Sheets("BasicData1").Range("B5").Select
    ActiveCell.FormulaR1C1 = MatlDescValue

Open in new window

0
 
LVL 25

Accepted Solution

by:
ProfessorJimJam earned 500 total points
ID: 40368389
i did not read your question correctly.

now here you go.  to put them all in one line see code below


 Sheets("BasicData1").Range("B5").Value = session.findbyid("wnd[0]/usr/tabsTABSPR1/tabpSP02/ssubTABFRA1:SAPLMGMM:2004/subSUB1:SAPLMGD1:1002/txtMAKT-MAKTX").Text 'Matl Description

Open in new window

0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:RWayneH
ID: 40368395
Does it have to select B5?  Could I do something like:
Sheets("BasicData1").Range("B5") = MatlDescValue    ?  I just would like to eliminate lines that are not needed.
0
 
LVL 25

Expert Comment

by:ProfessorJimJam
ID: 40368400
the last code i posted, is not selecting anything. it is using the ".Value" Property .

you cannot use Sheets("BasicData1").Range("B5") = MatlDescValue

instead you can use

Sheets("BasicData1").Range("B5").Value = MatlDescValue
0
 

Author Closing Comment

by:RWayneH
ID: 40368424
Yup worked great...   I need to focus on combining lines of code... speeds up the process and makes them easy to read.
THANKS!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

762 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

22 Experts available now in Live!

Get 1:1 Help Now