473,666 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need help to activate macro with clearcontents and need to protect sheet

1 New Member
May u help us to my code with clearcontent of specific column that need to clear content and protect sheet.Thank you

This is my code
Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function URLDownloadToFi le Lib "urlmon" Alias "URLDownloadToF ileA" (ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
#Else
Private Declare Function URLDownloadToFi le Lib "urlmon" Alias "URLDownloadToF ileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
#End If

Sub DownloadFiles()
Call ClearContents

Dim sh As Worksheet, DownloadFolder As String, lastrow As Long, SpecialChar() As String, SpecialCharFoun d As Double, asdf As Integer, ms As Workbook, digital As Workbook, fdsa As Integer
Dim FilePath As String, i As Long, j As Integer, Result As Long, CountErrors As Long, actvewkb As Workbook, ceel As Excel.Range
Set actvewkb = ActiveWorkbook
Sheets("Schedul e").Activate
asdf = Cells(Rows.Coun t, "A").End(xlUp). Row
Range("A2:AT" & asdf).ClearCont ents

Result = URLDownloadToFi le(0, "http:\\theconn ection.onsemi.c om\manufacturin g\ospi\cal_PM\" & _
"production_con trol\Shop Floor Schedule By Tester\FT_Digit al.xlsx", "C:\autodispatc h\FT_Digital.xl sx", 0, 0)
Call LastModifiedFil e
Set digital = ActiveWorkbook
Range("A11:AT50 00").Copy
actvewkb.Activa te
Sheets("Schedul e").Activate
Range("A2").Pas teSpecial xlPasteValuesAn dNumberFormats
asdf = Cells(Rows.Coun t, "A").End(xlUp). Row

Call ForeverLooping( asdf, 0)

Application.Dis playAlerts = False
digital.Close
Application.Dis playAlerts = True

Result = URLDownloadToFi le(0, "http:\\theconn ection.onsemi.c om\manufacturin g\ospi\cal_PM\" & _
"production_con trol\Shop Floor Schedule By Tester\FT_MS.xl sx", "C:\autodispatc h\FT_MS.xlsx", 0, 0)

Call LastModifiedFil e

Set ms = ActiveWorkbook
Sheets("T2K").A ctivate
asdf = Cells(Rows.Coun t, "A").End(xlUp). Row
Range("A10:AT" & asdf).Copy
actvewkb.Activa te
Sheets("Schedul e").Activate
fdsa = Cells(Rows.Coun t, "A").End(xlUp). Row
Range("A" & fdsa + 1).PasteSpecial xlPasteValuesAn dNumberFormats
asdf = Cells(Rows.Coun t, "A").End(xlUp). Row

Call ForeverLooping( asdf, fdsa)

ms.Activate
Sheets("UFLX"). Activate
asdf = Cells(Rows.Coun t, "A").End(xlUp). Row
Range("A18:AT" & asdf).Copy
actvewkb.Activa te
Sheets("Schedul e").Activate
fdsa = Cells(Rows.Coun t, "A").End(xlUp). Row
Range("A" & fdsa + 1).PasteSpecial xlPasteValuesAn dNumberFormats
asdf = Cells(Rows.Coun t, "A").End(xlUp). Row
Call ForeverLooping( asdf, fdsa)
Application.Dis playAlerts = False
ms.Close
Application.Dis playAlerts = True

Call FineTuning

Range("A2").Sel ect
End Sub

Sub ClearContents()
Dim lastrow As Integer
lastrow = Cells(Rows.Coun t, "A").End(xlUp). Row
Sheets("UPDATE" ).Activate
Range("A4:E" & lastrow).ClearC ontents
End Sub

Sub ForeverLooping( ByVal asdf As Integer, ByVal i As Integer)
Dim x As Integer
If i = 0 Then i = 2
For x = i To asdf
If Range("A" & x).Text <> "" Then
If Range("A" & x + 1).Text = "" Then
Range("A" & x + 1).EntireRow.De lete
asdf = Cells(Rows.Coun t, "A").End(xlUp). Row
If x = asdf Then
Exit For
Else
x = x - 1
End If
End If
End If
Next
End Sub

Sub FineTuning()
Dim lastrow As Integer, x As Integer
Dim neValues As Range, neFormulas As Range, MyRange As Range
lastrow = Cells(Rows.Coun t, "A").End(xlUp). Row
For x = 2 To lastrow
Range("B" & x).Select
Set MyRange = Columns("B:AT")
On Error Resume Next
Set neValues = Intersect(Activ eCell.EntireRow .SpecialCells(x lConstants), MyRange)
Set neFormulas = Intersect(Activ eCell.EntireRow .SpecialCells(x lFormulas), MyRange)
On Error GoTo 0
If neValues Is Nothing And neFormulas Is Nothing Then
Range("B" & x).EntireRow.De lete
End If
Next
End Sub

Public Sub LastModifiedFil e()
Dim dirName As String, fName As String, fileTime As Date, fileName As String, latestFile As String
dirName = "C:\autodispatc h\"
fName = Dir(dirName & "\*.xlsx*")
latestFile = fName
fileTime = FileDateTime(di rName & fName)
While fName <> ""
If FileDateTime(di rName & fName) > fileTime Then
latestFile = fName
fileTime = FileDateTime(di rName & fName)
End If
fName = Dir()
Wend
If latestFile = "" Then
MsgBox "There are no files in the directory"
Else
Application.Dis playAlerts = False
Workbooks.Open "C:\autodispatc h\" & latestFile, UpdateLinks:=xl UpdateLinksAlwa ys
Application.Dis playAlerts = True
End If

x:
If Err.Description <> "" Then MsgBox "Process did not detect the directory. Process will end.", vbCritical, "OEE Report Generator"

End Sub
Jun 28 '18 #1
0 2088

Sign in to post your reply or Sign up for a free account.

Similar topics

9
4030
by: Edward S | last post by:
I budget for a Project in an Excel sheet as illustrated below. The months below are usually a 2 year period i.e. 24 months, though it could be over 24 months depending upon a Project. I then need to input this in an Access database, where I do a comparison with the Actual cost. The table “TblBudget” in Access is made of 4 fields, namely: (1) CostElement (2) CostCenter (3) Month (4) Amount$. At the moment this method is very cumbersome....
1
4555
by: Giganews | last post by:
I have an Access 97 database in which I am running an Excel macro through automation. The macro in Excel is as follows: Worksheets("Sheet1").Protect Password:="****", DrawingObjects:=True, Contents:=True, Scenarios:=True When I call this macro from the database all works fine except when I recorded the macro I deselected the "Select locked cells" option under the "Allow all users of this worksheet to:" section but yet when I access the...
6
1481
by: Ashwani | last post by:
consider A is of type char *A there is this function X which takes variable number of "char * " arguments, so X can be called like X (A) or X(A, A) or X(A, A, A) and so on I have to call this function X from different places in the code.
0
863
by: mju | last post by:
Sorry, I know that there has been discussions related to this topic, but havent found the same situation. I have data coming from the server to be displayed within the Excel sheet, by selecting items from a listbox. I have defined index in order to keep track on the items to be placed in their own columns in sheet, does anybody have solution how to put each entity in its own column using indexes? I get the data right but showing it causes...
1
2180
by: simple25 | last post by:
I looked up my system information and discovered that my BIOS is dated back to 4/25/2003 version 4. I looked up the website for where my computer is manufactured and found that there is a now a version 10. I am well aware that updating your BIOS can cause major problems if it is not done correctly. So my question is do I need to update my BIOS to version 10? Would it be best? If I do, can I jump from version 4 straight to version...
4
16095
by: shara | last post by:
Hello, I have a php script that outputs an excel sheet.The user has to download macro every time he wants to run the macro on the excel sheet. Is there anything in php where the code downloads macro also along with the excel sheet or something like a button in excel sheet itself, clicking on which the macro runs on the excel sheet. Any help is well appreciated. Thanks&Regards, Shara.
0
1606
by: printline | last post by:
Hello I have the following macro for outlook: Dim oApp As Application Dim oNS As NameSpace Dim oMsg As Object Dim bDoAction As Boolean Dim oAttachments As Outlook.Attachments
1
1719
by: canada18 | last post by:
I am trying to call a macro written in excel and calling from VBA code. Macro is in worksshet within a workbook. Error message is : Object variable or with block variable not set Any idea what it is complaining about?
1
1049
by: Joey Ballard | last post by:
I have 6 workbooks, some with multiple sheets. I need to pull data from two cells from each of the sheets in each workbook into another workbook how can i do this.?
2
1930
by: simonjames | last post by:
I have an Excel workbook, which is an order form using tick boxes, if "ticked"(true)the item seleted data appears into other worksheets. If it returns "" (blank)then I want to delete the blank rows in various other worksheets within the workbook. Can someone please help with some code I have the following code which will work in 1 worksheet but i can not get it to do the same in the other worksheets Sub Deleterow() Dim rngstart As Range...
0
8444
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7386
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5664
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.