我需要时间来改变用户使用VBA输入的内容

时间:2016-07-22 16:24:35

标签: excel vba excel-vba

所以在excel sheet1上我有一个我需要的信息列表。(有一张图片)在那里我们有开始时间和执行时间。此信息将传递给sheet3,我希望根据执行时间更改结束时间。例如,如果用户输入开始时间=下午1:00并且执行时间= 30分钟。我希望代码放在第3页=下午1:30的结束时间。这是我目前的代码:enter image description here

Sub findData()
    Dim workflow As String
    Dim finalrow As Integer
    Dim i As Integer

    With Sheets("Sheet1")
        workflow = .Range("C5").Value
        servergri = .Range("C9").Value
        gridf = .Range("C9").Value
        StartTime = .Range("c11").Value
    End With

    With Sheets("Sheet3")
        finalrow = .Range("C" & Rows.Count).End(xlUp).Row

        For i = 5 To finalrow
            If .Cells(i, 3) = workflow And (.Cells(i, 4) = servergri Or .Cells(i, 5) = gridf) Then

                .Rows(i).Insert
                'Add new information to the new row.
                'The new row number is still = i

                .Cells(i, 3) = workflow
                .Cells(i, 4) = servergri
                .Cells(i, 6) = StartTime
                    .Cells(i, 3).Resize(2, 4).Interior.ColorIndex = 8


                'If you only want to add one row then your should exit the loop
                Exit For
            End If
        Next
    End With

End Sub

1 个答案:

答案 0 :(得分:0)

这样做,但您需要确保用户仅以分钟为单位输入时间。 EG“60”持续1小时或“15”持续15分钟。他们不应该输入标签。

getwd()
setwd("C:/_R")
library(maptools)
require(rgdal)
# Read SHAPEFILE.shp from the current working directory (".")
points2010 <- readOGR(dsn = "C:/_R", layer = "points_2010")
metro <- readOGR(dsn = "C:/_R", layer = "selection")
plot(points2010)
plot(metro, axes=TRUE)
head(points2010)

library("rgeos")
ohio.metro <- spTransform(points2010, CRS("+proj=longlat +datum=WGS84"))
plot(ohio.metro, axes=TRUE)

ohio.metro$COUNTYFP10<-substr(ohio.metro$id,3,5)
countylist<-unique(ohio.metro$COUNTYFP10)
# "035" "055" "085" "093" "103"
ohio.county035 <- subset( ohio.metro, COUNTYFP10 == "035"  )
ohio.county055 <- subset( ohio.metro, COUNTYFP10 == "055"  )
ohio.county085 <- subset( ohio.metro, COUNTYFP10 == "085"  )
ohio.county093 <- subset( ohio.metro, COUNTYFP10 == "093"  )
ohio.county103 <- subset( ohio.metro, COUNTYFP10 == "103"  )

plot(ohio.metro$COUNTYFP10) #counties in the metro
plot(ohio.county035$COUNTYFP10) # counties inthe county

plot(ohio.metro) #counties in the metro
plot(ohio.county035) # counties inthe county

#get the coordinats for the Great circle command
ohio.metro.coords <- ohio.metro@coords
ohio.county035.coords <- ohio.county035@coords
ohio.county055.coords <- ohio.county055@coords
ohio.county085.coords <- ohio.county085@coords
ohio.county093.coords <- ohio.county093@coords
ohio.county103.coords <- ohio.county103@coords

library(fields)
great_circle<-rdist.earth(ohio.county035.coords,ohio.metro.coords,miles=TRUE, R=NULL) #works
great_circle<-rdist.earth(ohio.county055.coords,ohio.metro.coords,miles=TRUE, R=NULL) #works
great_circle<-rdist.earth(ohio.county085.coords,ohio.metro.coords,miles=TRUE, R=NULL) #works
great_circle<-rdist.earth(ohio.county093.coords,ohio.metro.coords,miles=TRUE, R=NULL) #works
great_circle<-rdist.earth(ohio.county103.coords,ohio.metro.coords,miles=TRUE, R=NULL) #works

library(matrixStats)
bm<-rowMedians(great_circle)
head(bm)