Solved

Shorten VBA to one statement instead of three?

Posted on 2014-10-08
6
101 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
[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
  • 4
  • 2
6 Comments
 
LVL 26

Expert Comment

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

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 26

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 26

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
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.

630 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